home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Auth / Container.php < prev    next >
PHP Script  |  2004-03-24  |  5KB  |  178 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Martin Jansen <mj@php.net>                                  |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Container.php,v 1.15 2003/10/19 14:03:19 yavo Exp $
  20. //
  21.  
  22. define("AUTH_METHOD_NOT_SUPPORTED", -4);
  23.  
  24. /**
  25.  * Storage class for fetching login data
  26.  *
  27.  * @author   Martin Jansen <mj@php.net>
  28.  * @package  Auth
  29.  */
  30. class Auth_Container
  31. {
  32.  
  33.     /**
  34.      * User that is currently selected from the storage container.
  35.      *
  36.      * @access public
  37.      */
  38.     var $activeUser = "";
  39.  
  40.     // {{{ Constructor
  41.  
  42.     /**
  43.      * Constructor
  44.      *
  45.      * Has to be overwritten by each storage class
  46.      *
  47.      * @access public
  48.      */
  49.     function Auth_Container()
  50.     {
  51.     }
  52.  
  53.     // }}}
  54.     // {{{ fetchData()
  55.  
  56.     /**
  57.      * Fetch data from storage container
  58.      *
  59.      * Has to be overwritten by each storage class
  60.      *
  61.      * @access public
  62.      */
  63.     function fetchData() 
  64.     {
  65.     }
  66.  
  67.     // }}}
  68.     // {{{ verifyPassword()
  69.  
  70.     /**
  71.      * Crypt and verfiy the entered password
  72.      *
  73.      * @param  string Entered password
  74.      * @param  string Password from the data container (usually this password
  75.      *                is already encrypted.
  76.      * @param  string Type of algorithm with which the password from
  77.      *                the container has been crypted. (md5, crypt etc.)
  78.      *                Defaults to "md5".
  79.      * @return bool   True, if the passwords match
  80.      */
  81.     function verifyPassword($password1, $password2, $cryptType = "md5")
  82.     {
  83.         switch ($cryptType) {
  84.         case "crypt" :
  85.             return (($password2 == "**" . $password1) ||
  86.                     (crypt($password1, $password2) == $password2)
  87.                     );
  88.             break;
  89.  
  90.         case "none" :
  91.             return ($password1 == $password2);
  92.             break;
  93.  
  94.         case "md5" :
  95.             return (md5($password1) == $password2);
  96.             break;
  97.  
  98.         default :
  99.             if (function_exists($cryptType)) {
  100.                 return ($cryptType($password1) == $password2);
  101.             }
  102.             else if (method_exists($this,$cryptType)) { 
  103.                 return ($this->$cryptType($password1) == $password2);
  104.             } else {
  105.                 return false;
  106.             }
  107.             break;
  108.         }
  109.     }
  110.  
  111.     // }}}
  112.     // {{{ listUsers()
  113.  
  114.     /**
  115.      * List all users that are available from the storage container
  116.      */
  117.     function listUsers()
  118.     {
  119.         return AUTH_METHOD_NOT_SUPPORTED;
  120.     }
  121.  
  122.     /**
  123.      * Returns a user assoc array
  124.      *
  125.      * Containers which want should overide this
  126.      *
  127.      * @param string The username
  128.      */
  129.     function getUser($username)
  130.     {
  131.         $users = $this->listUsers();
  132.         if($users === AUTH_METHOD_NOT_SUPPORTED){
  133.             return(AUTH_METHOD_NOT_SUPPORTED);
  134.         }
  135.         for($i=0;$c = count($users),$i<$c;$i++){
  136.             if($users[$i]['username'] == $username){
  137.                 return($users[$i]);
  138.             }
  139.         }
  140.         return(false);
  141.         
  142.     }
  143.  
  144.     // }}}
  145.     // {{{ addUser()
  146.  
  147.     /**
  148.      * Add a new user to the storage container
  149.      *
  150.      * @param string Username
  151.      * @param string Password
  152.      * @param array  Additional information
  153.      *
  154.      * @return boolean
  155.      */
  156.     function addUser($username, $password, $additional=null)
  157.     {
  158.         return AUTH_METHOD_NOT_SUPPORTED;
  159.     }
  160.  
  161.     // }}}
  162.     // {{{ removeUser()
  163.  
  164.     /**
  165.      * Remove user from the storage container
  166.      *
  167.      * @param string Username
  168.      */
  169.     function removeUser($username)
  170.     {
  171.         return AUTH_METHOD_NOT_SUPPORTED;
  172.     }
  173.  
  174.     // }}}
  175.  
  176. }
  177. ?>
  178.